home *** CD-ROM | disk | FTP | other *** search
Wrap
/* Manual Shift Layout Sample Program By Eric Mader, After Mike Fairman, Oliver Steele et. al. */ /* Copyright ©1989, 1990, 1991 Apple Computer, Inc. All rights reserved. */ #ifndef THINK_C #include <Quickdraw.h> #include <Fonts.h> #include <Windows.h> #include <Dialogs.h> #include <Events.h> #include <Memory.h> #include <Menus.h> #include <String.h> #include <Desk.h> #include <Script.h> #include <ToolUtils.h> #define thePort qd.thePort #define screenBits qd.screenBits #endif #include "graphics libraries.h" #include "qd library.h" #include "graphics debugging.h" #include "graphics routines.h" #include "graphics toolbox.h" #include "layout feature constants.h" #include "layout types.h" #include "layout routines.h" #include "layout library.h" /* This macro is useful for constructing fixed values */ #define f(a,b) (((fixed) (a) << 16) + (b)) /* various menu and dialog things */ enum {aboutDLOG = 128, appleMenuID = 128, fileMenuID, editMenuID}; /* resource ID's */ enum {okButton = 1, showsItem, authorItem}; enum { /* Apple Menu */ aboutCommand = 1, /* File Menu */ quitCommand = 1, /* Edit Menu */ undoCommand = 1, cutCommand, copyCommand, pasteCommand, clearCommand}; WindowPtr myWindow, whichWindow; gxViewPort myPort; Rect qdWindowRect; Rect growRect = {40, 40, 32767, 32767}; Rect bigRect = {-32768, -32768, 32767, 32767}; gxRectangle windowRect; MenuHandle appleMenu, fileMenu, editMenu; Boolean done = false; gxColor colorWhite = xRGB (0xFFFF, 0xFFFF, 0xFFFF); /* white */ gxColor hsvInitial = xHSV (0, 0xFFFF, 0xFFFF); /* red */ static void ShowAboutBox () { GrafPtr savePort; DialogPtr theDialog; short itemType; Handle itemHdl; Rect itemRect; short itemHit; GetPort(&savePort); theDialog = GetNewDialog(aboutDLOG, nil, (WindowPtr) -1); SetPort(theDialog); GetDItem(theDialog, authorItem, &itemType, &itemHdl, &itemRect); SetIText(itemHdl, (StringPtr) "\pRice Dream"); GetDItem(theDialog, showsItem, &itemType, &itemHdl, &itemRect); SetIText(itemHdl, (StringPtr) "\pManual Shifting"); do { ModalDialog(nil, &itemHit); } while (itemHit != okButton); CloseDialog(theDialog); SetPort(savePort); } static void SetupMenus () { InsertMenu (appleMenu = GetMenu (appleMenuID), 0); AddResMenu (appleMenu, (ResType) 'DRVR'); InsertMenu (fileMenu = GetMenu (fileMenuID), 0); InsertMenu (editMenu = GetMenu (editMenuID), 0); DrawMenuBar (); } static void DoMenuCommand (long mResult) { short theItem = LoWord (mResult), theMenuID = HiWord (mResult); GrafPtr savePort; Str255 daName; switch (theMenuID) { case appleMenuID: if (theItem == aboutCommand) ShowAboutBox (); else { GetItem (appleMenu, theItem, daName); GetPort (&savePort); (void) OpenDeskAcc (daName); SetPort (savePort); } break; case fileMenuID: if (theItem == quitCommand) done = true; break; case editMenuID: break; } HiliteMenu (0); } static short StrLength(char *s) {short len; for (len = 0; *s++ != 0; len++) ; return len; } void main() { EventRecord theEvent; gxShape layout, whiteOut; gxRunControls controls; gxLayoutOptions gxLayoutOptions; gxStyle glyphStyles[2]; char *text1 = "Office"; char *text2 = "AWAY"; char *textRuns[2]; short level0 = 0, textLengths[2], totalLength; gxPoint posn; GDHandle max; short mbh = GetMBarHeight (); MaxApplZone(); MoreMasters(); MoreMasters(); SetGraphicsLibraryErrors(); SetGraphicsLibraryNotices (); /* GXSetValidation(gxInternalValidation | gxStructureValidation | gxNoMemoryManagerValidation); /* uncomment this for less speed and more error-checking */ InitGraf(&thePort); InitFonts(); InitWindows(); InitMenus (); InitCursor(); SetupMenus (); /* find the deepest monitor, and make a window that just covers it */ max = GetMaxDevice (&bigRect); qdWindowRect = (**max).gdRect; /* bring it down one mbh for the header, maybe another if on main screen */ if (qdWindowRect.top == 0 && qdWindowRect.left == 0) qdWindowRect.top += mbh; qdWindowRect.top += mbh; InsetRect (&qdWindowRect, 4, 4); ShortRectToFixed (&qdWindowRect, &windowRect); myWindow = NewWindow(nil, &qdWindowRect, (StringPtr) "\pShift Layout Sample", true, documentProc, (WindowPtr) -1L, true, 0L); myPort = GXNewWindowViewPort (myWindow); SetDefaultViewPort (myPort); /* When we want to erase the whole window, we just GXDrawShape (whiteOut). */ whiteOut = GXNewShape (gxFullType); GXSetShapeColor (whiteOut, &colorWhite); /* gxInitialize the textRuns array */ textRuns[0] = text1; textRuns[1] = text2; /* gxInitialize the textLengths array */ textLengths[0] = StrLength (text1); textLengths[1] = StrLength (text2); totalLength = textLengths[0] + textLengths[1]; /* Make a default gxLayoutOptions and gxRunControls */ InitializeLayoutOptions (&gxLayoutOptions); InitializeRunControls (&controls); /* Position the layout half way down the left edge of the window. Set the layout's width to the window's width and set the flushness to 1/2, this will cause the layout to center in the window. */ gxLayoutOptions.width = windowRect.right - windowRect.left; gxLayoutOptions.flush = fract1/2; posn.x = 0; posn.y = (windowRect.bottom - windowRect.top) / 2; /* run 0 is 60 pt. Times Roman */ glyphStyles[0] = NewLayoutStyle((char *) "\pTimes Roman", ff(60), 0, &controls, nil, 0, nil); /* Set the cross stream shift to 30 to raise the text 30 points, and the with stream shift to -4 to move the text 4 points closer together than normal kerning would move it. */ controls.crossStreamShift = ff(30); controls.beforeWithStreamShift = -ff(4); /* run 1 is 30 pt. Times Roman */ glyphStyles[1] = NewLayoutStyle((char *) "\pTimes Roman", ff(30), 0, &controls, nil, 0, nil); /* Build and draw the layout. */ layout = GXNewLayout( 2, textLengths, (void *) textRuns, 2, textLengths, glyphStyles, 1, &totalLength, &level0, &gxLayoutOptions, &posn); GXDrawShape (layout); /* Now just spin in a simple event loop until it's time to go */ while (!done) { if (WaitNextEvent(everyEvent, &theEvent, 0, nil)) { switch(theEvent.what) { case mouseDown: switch (FindWindow(theEvent.where, &whichWindow)) { case inSysWindow: SystemClick(&theEvent, whichWindow); break; case inMenuBar: DoMenuCommand (MenuSelect (theEvent.where)); break; case inDrag: DragWindow(whichWindow, theEvent.where, &screenBits.bounds); break; case inGrow: { register long newSize; newSize = GrowWindow(whichWindow, theEvent.where, &growRect); SizeWindow(whichWindow, LoWord(newSize), HiWord(newSize), true); } break; case inGoAway: if (TrackGoAway(whichWindow, theEvent.where)) done = true; break; case inContent: if (whichWindow != FrontWindow()) SelectWindow(whichWindow); break; } break; case keyDown: case autoKey: if (myWindow == FrontWindow () && theEvent.modifiers & cmdKey) DoMenuCommand (MenuKey (theEvent.message & charCodeMask)); break; case updateEvt: BeginUpdate((WindowPtr)theEvent.message); GXDrawShape (whiteOut); GXDrawShape (layout); EndUpdate((WindowPtr)theEvent.message); break; } } } /* dispose everything we've allocated. */ GXDisposeShape(layout); GXDisposeStyle (glyphStyles[0]); GXDisposeStyle (glyphStyles[1]); DisposeWindow(myWindow); GXDisposeShape (whiteOut); }